<!-- 页面外套 -->
<div class="page-wrapper" id="setup_attendance_worktime">

    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped" id="setup_attendance_worktime_datagrid">

        <!-- 工具条组 -->
        <div class="tool-group">
            <div class="tool-deal">
                <label><button class="btn btn-primary" id="setup_attendance_worktime_add_btn"> <i class="icon icon-plus"></i> 添加</button></label>
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- tool-group -->

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>
    <!-- datagrid -->

    <!-- 添加盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="setup_attendance_worktime_add_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">添加</h4>
                </div>
                <div class="modal-body">
                    <form class="container form-horizontal need-hidden-box">
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_add_name">班次名称</label>
                            <div class="col-sm-8"><input type="text" class="form-control" id="setup_attendance_worktime_add_name"></div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_add_type">班次类型</label>
                            <div class="col-sm-8">
                                <select class="form-control" id="setup_attendance_worktime_add_type">
                                    <option value="1">一天一次</option>
                                    <option value="2">一天两次</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_add_time1">班次时间</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <span class="input-group-addon">上班时间1</span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_add_time1">
                                </div>
                                <div class="form-control-floor"></div>
                                <div class="input-group">
                                    <span class="input-group-addon">下班时间1</span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_add_time2">
                                </div>
                                <div class="need-hidden">
                                    <div class="form-control-floor"></div>
                                    <div class="input-group">
                                        <span class="input-group-addon">上班时间2</span>
                                        <input type="time" class="form-control" id="setup_attendance_worktime_add_time3">
                                    </div>
                                    <div class="form-control-floor"></div>
                                    <div class="input-group">
                                        <span class="input-group-addon">下班时间2</span>
                                        <input type="time" class="form-control" id="setup_attendance_worktime_add_time4">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group require need-shown">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_add_noon1">午休时间</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <span class="input-group-addon">开始时间 &nbsp; </span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_add_noon1">
                                </div>
                                <div class="form-control-floor"></div>
                                <div class="input-group">
                                    <span class="input-group-addon">结束时间 &nbsp; </span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_add_noon2">
                                </div>
                            </div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_add_flex1">晚走晚到</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <span class="input-group-addon">第一天下班晚走</span>
                                    <input type="number" class="form-control" id="setup_attendance_worktime_add_flex1">
                                    <span class="input-group-addon">分钟</span>
                                </div>
                                <div class="form-control-floor"></div>
                                <div class="input-group">
                                    <span class="input-group-addon">第二天上班晚到</span>
                                    <input type="number" class="form-control" id="setup_attendance_worktime_add_flex2">
                                    <span class="input-group-addon">分钟</span>
                                </div>
                            </div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_add_late">旷工迟到</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input type="number" class="form-control" id="setup_attendance_worktime_add_late">
                                    <span class="input-group-addon">分钟</span>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary"  id="setup_attendance_worktime_add_submit">提交</button>
                </div>
            </div>
        </div>
    </div>
    <!-- setup_attendance_worktime_add_box -->

    <!-- 修改盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="setup_attendance_worktime_edit_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">修改</h4>
                </div>
                <div class="modal-body">
                    <form class="container form-horizontal need-hidden-box">
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_edit_name">班次名称</label>
                            <div class="col-sm-8"><input type="text" class="form-control" id="setup_attendance_worktime_edit_name"></div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_edit_type">班次类型</label>
                            <div class="col-sm-8">
                                <select class="form-control" id="setup_attendance_worktime_edit_type">
                                    <option value="1">一天一次</option>
                                    <option value="2">一天两次</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_edit_time1">班次时间</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <span class="input-group-addon">上班时间1</span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_edit_time1">
                                </div>
                                <div class="form-control-floor"></div>
                                <div class="input-group">
                                    <span class="input-group-addon">下班时间1</span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_edit_time2">
                                </div>
                                <div class="need-hidden">
                                    <div class="form-control-floor"></div>
                                    <div class="input-group">
                                        <span class="input-group-addon">上班时间2</span>
                                        <input type="time" class="form-control" id="setup_attendance_worktime_edit_time3">
                                    </div>
                                    <div class="form-control-floor"></div>
                                    <div class="input-group">
                                        <span class="input-group-addon">下班时间2</span>
                                        <input type="time" class="form-control" id="setup_attendance_worktime_edit_time4">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group require need-shown">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_edit_noon1">午休时间</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <span class="input-group-addon">开始时间 &nbsp; </span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_edit_noon1">
                                </div>
                                <div class="form-control-floor"></div>
                                <div class="input-group">
                                    <span class="input-group-addon">结束时间 &nbsp; </span>
                                    <input type="time" class="form-control" id="setup_attendance_worktime_edit_noon2">
                                </div>
                            </div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_edit_flex1">晚走晚到</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <span class="input-group-addon">第一天下班晚走</span>
                                    <input type="number" class="form-control" id="setup_attendance_worktime_edit_flex1">
                                    <span class="input-group-addon">分钟</span>
                                </div>
                                <div class="form-control-floor"></div>
                                <div class="input-group">
                                    <span class="input-group-addon">第二天上班晚到</span>
                                    <input type="number" class="form-control" id="setup_attendance_worktime_edit_flex2">
                                    <span class="input-group-addon">分钟</span>
                                </div>
                            </div>
                        </div>
                        <div class="form-group require">
                            <label class="col-sm-2 required" for="setup_attendance_worktime_edit_late">旷工迟到</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input type="number" class="form-control" id="setup_attendance_worktime_edit_late">
                                    <span class="input-group-addon">分钟</span>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary"  id="setup_attendance_worktime_edit_submit">提交</button>
                </div>
            </div>
        </div>
    </div>
    <!-- setup_attendance_worktime_edit_box -->

    <!-- 删除盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="setup_attendance_worktime_dele_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <p class="text-danger"><i class="icon icon-warning-sign"></i> 是否删除？</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-danger"  id="setup_attendance_worktime_dele_submit">提交</button>
                </div>
            </div>
        </div>
    </div>
    <!-- setup_attendance_worktime_dele_box -->

</div>
<!-- page-wrapper -->

<script>
$(function(){
   
    //变量声明-----------------------------------------------------------------------------------------------
    var 
    setup_attendance_worktime               = $("#setup_attendance_worktime"),              //页面ID
    setup_attendance_worktime_datagrid      = $("#setup_attendance_worktime_datagrid"),     //数据表格
    //添加
    setup_attendance_worktime_add_btn       = $("#setup_attendance_worktime_add_btn"),      //添加按钮
    setup_attendance_worktime_add_box       = $("#setup_attendance_worktime_add_box"),      //添加盒子
    setup_attendance_worktime_add_submit    = $("#setup_attendance_worktime_add_submit"),   //添加提交
    setup_attendance_worktime_add_name      = $("#setup_attendance_worktime_add_name"),     //班次名称
    setup_attendance_worktime_add_type      = $("#setup_attendance_worktime_add_type"),     //班次类型
    setup_attendance_worktime_add_time1     = $("#setup_attendance_worktime_add_time1"),    //上班时间1
    setup_attendance_worktime_add_time2     = $("#setup_attendance_worktime_add_time2"),    //上班时间2
    setup_attendance_worktime_add_time3     = $("#setup_attendance_worktime_add_time3"),    //上班时间3
    setup_attendance_worktime_add_time4     = $("#setup_attendance_worktime_add_time4"),    //上班时间4
    setup_attendance_worktime_add_noon1     = $("#setup_attendance_worktime_add_noon1"),    //午休时间1
    setup_attendance_worktime_add_noon2     = $("#setup_attendance_worktime_add_noon2"),    //午休时间2
    setup_attendance_worktime_add_flex1     = $("#setup_attendance_worktime_add_flex1"),    //晚走晚到1
    setup_attendance_worktime_add_flex2     = $("#setup_attendance_worktime_add_flex2"),    //晚走晚到2
    setup_attendance_worktime_add_late      = $("#setup_attendance_worktime_add_late"),     //旷工迟到
    //修改
    setup_attendance_worktime_edit_box      = $("#setup_attendance_worktime_edit_box"),     //修改盒子
    setup_attendance_worktime_edit_submit   = $("#setup_attendance_worktime_edit_submit"),  //修改提交
    setup_attendance_worktime_edit_name     = $("#setup_attendance_worktime_edit_name"),    //班次名称
    setup_attendance_worktime_edit_type     = $("#setup_attendance_worktime_edit_type"),    //班次类型
    setup_attendance_worktime_edit_time1    = $("#setup_attendance_worktime_edit_time1"),   //上班时间1
    setup_attendance_worktime_edit_time2    = $("#setup_attendance_worktime_edit_time2"),   //上班时间2
    setup_attendance_worktime_edit_time3    = $("#setup_attendance_worktime_edit_time3"),   //上班时间3
    setup_attendance_worktime_edit_time4    = $("#setup_attendance_worktime_edit_time4"),   //上班时间4
    setup_attendance_worktime_edit_noon1    = $("#setup_attendance_worktime_edit_noon1"),   //午休时间1
    setup_attendance_worktime_edit_noon2    = $("#setup_attendance_worktime_edit_noon2"),   //午休时间2
    setup_attendance_worktime_edit_flex1    = $("#setup_attendance_worktime_edit_flex1"),   //晚走晚到1
    setup_attendance_worktime_edit_flex2    = $("#setup_attendance_worktime_edit_flex2"),   //晚走晚到2
    setup_attendance_worktime_edit_late     = $("#setup_attendance_worktime_edit_late"),    //旷工迟到
    //删除
    setup_attendance_worktime_dele_box      = $("#setup_attendance_worktime_dele_box"),     //删除盒子
    setup_attendance_worktime_dele_submit   = $("#setup_attendance_worktime_dele_submit");  //删除提交

    //接口对象-----------------------------------------------------------------------------------------------
    if( window.STATE == "local" ){

        //本地接口
        var setup_attendance_worktime_api = {
            datagrid   : LOCAL + "Test/Setup/Attendance/worktime.json",                         //数据表格
            modal_edit : LOCAL + "Test/Setup/Attendance/worktime_edit.json",                    //修改盒子
        }

    } else if ( window.STATE == "route" ){

        //远程接口
        var setup_attendance_worktime_api = {
            datagrid   : LOCAL + "Test/Setup/Attendance/worktime.json",                         //数据表格
            modal_edit : LOCAL + "Test/Setup/Attendance/worktime_edit.json",                    //修改盒子
        }

    }

    //数据表格-----------------------------------------------------------------------------------------------
    setup_attendance_worktime_datagrid.datagrid({
        height      : zui_datagrid_height(setup_attendance_worktime_datagrid),
        sortable    : false,
        cache       : false,
        showRowIndex: true,
        configs     : {
            R0:{className:"text-center"},
            C1:{className:"cell-hidden"}
        },
        states      : {
            pager           : {
                page        : 1,
                recPerPage  : window.REC_PER_PAGE,
            }
        },
        dataSource : {
            cols   : [
                {name:"id",      label:"ID",      width:49 },
                {name:"workname",label:"班次名称",width:150},
                {name:"worktime",label:"考勤时间",width:200},
                {name:"operate", label:"操作",    width:150,
                    html:true,
                    valueOperator : {
                        getter : function(dataValue,cell){
                            var temp = `
                                <a class="setup_attendance_worktime_edit_btn" rowIndex="${cell.rowIndex}" state="${dataValue}">修改</a>
                                <a class="setup_attendance_worktime_dele_btn" rowIndex="${cell.rowIndex}">删除</a>
                            `;
                           return temp;
                        }
                    }
                }
            ],
            remote : function(){
                return {
                    url     : setup_attendance_worktime_api.datagrid,
                    type    : "POST",
                    dataType: "json",
                }
            }
        }
    });

    //变量声明-----------------------------------------------------------------------------------------------
    var
    setup_attendance_worktime_datagrid_obj   = setup_attendance_worktime_datagrid.data("zui.datagrid"),   //表格对象
    setup_attendance_worktime_edit_btn       = ".setup_attendance_worktime_edit_btn",                     //修改按钮
    setup_attendance_worktime_dele_btn       = ".setup_attendance_worktime_dele_btn";                     //删除按钮

    //类型切换-隐藏相应字段----------------------------------------------------------------------------------
    $(".need-hidden").addClass("hidden");   //默认隐藏
    $("#setup_attendance_worktime_add_type,#setup_attendance_worktime_edit_type").change(function(){
        var need_hidden = $(this).parents(".need-hidden-box").find(".need-hidden");
        var need_shown  = $(this).parents(".need-hidden-box").find(".need-shown");
        if( $(this).val()=="1" ){
            need_hidden.addClass("hidden");
            need_shown.removeClass("hidden");
        } else {
            need_hidden.removeClass("hidden");
            need_shown.addClass("hidden");
        }
    });

    //添加按钮-----------------------------------------------------------------------------------------------
    setup_attendance_worktime_add_btn.click(function(){
        common_form_reset();
        setup_attendance_worktime_add_box.modal("show");
    });
    //添加提交
    setup_attendance_worktime_add_submit.click(function(){
 
        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : {
                name  : setup_attendance_worktime_add_name.val(),
                type  : setup_attendance_worktime_add_type.val(),
                time1 : setup_attendance_worktime_add_time1.val(),
                time2 : setup_attendance_worktime_add_time2.val(),
                time3 : setup_attendance_worktime_add_time3.val(),
                time4 : setup_attendance_worktime_add_time4.val(),
                noon1 : setup_attendance_worktime_add_noon1.val(),
                noon2 : setup_attendance_worktime_add_noon2.val(),
                flex1 : setup_attendance_worktime_add_flex1.val(),
                flex2 : setup_attendance_worktime_add_flex2.val(),
                late  : setup_attendance_worktime_add_late.val(),
            },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(setup_attendance_worktime_datagrid_obj,setup_attendance_worktime_api.datagrid);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

    //修改按钮-----------------------------------------------------------------------------------------------
    $(document).on("click",setup_attendance_worktime_edit_btn,function(){
  
        //数据ID
        var data_id    = zui_datagrid_get_id($(this).attr("rowIndex"));
        var data_state = $(this).attr("state");

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : { id:data_id },
            success : function(data){
                if( data.status>0 ){

                    //类型影响
                    var test_type = 2;
                    if( test_type == 2 ){
                        setup_attendance_worktime_edit_box.find(".need-hidden").removeClass("hidden");
                        setup_attendance_worktime_edit_box.find(".need-shown" ).addClass("hidden");
                    }
                    //数据赋值
                    setup_attendance_worktime_edit_name.val(  data.message ),
                    setup_attendance_worktime_edit_type.val(  test_type    ),
                    setup_attendance_worktime_edit_time1.val( "09:00"      ),
                    setup_attendance_worktime_edit_time2.val( "09:00"      ),
                    setup_attendance_worktime_edit_time3.val( "09:00"      ),
                    setup_attendance_worktime_edit_time4.val( "09:00"      ),
                    setup_attendance_worktime_edit_noon1.val( "09:00"      ),
                    setup_attendance_worktime_edit_noon2.val( "09:00"      ),
                    setup_attendance_worktime_edit_flex1.val( "60"         ),
                    setup_attendance_worktime_edit_flex2.val( "60"         ),
                    setup_attendance_worktime_edit_late.val(  "60"         ),

                    //其他操作
                    setup_attendance_worktime_edit_submit.attr("dataId",data_id);  //数据ID传值
                    setup_attendance_worktime_edit_box.modal("show");              //盒子显示

                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });
    //修改提交
    setup_attendance_worktime_edit_submit.click(function(){

        //数据ID
        var data_id = $(this).attr("dataId");

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : { 
                id    : data_id,
                name  : setup_attendance_worktime_edit_name.val(),
                type  : setup_attendance_worktime_edit_type.val(),
                time1 : setup_attendance_worktime_edit_time1.val(),
                time2 : setup_attendance_worktime_edit_time2.val(),
                time3 : setup_attendance_worktime_edit_time3.val(),
                time4 : setup_attendance_worktime_edit_time4.val(),
                noon1 : setup_attendance_worktime_edit_noon1.val(),
                noon2 : setup_attendance_worktime_edit_noon2.val(),
                flex1 : setup_attendance_worktime_edit_flex1.val(),
                flex2 : setup_attendance_worktime_edit_flex2.val(),
                late  : setup_attendance_worktime_edit_late.val(),
             },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(setup_attendance_worktime_datagrid_obj,setup_attendance_worktime_api.datagrid);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });
    //删除按钮-----------------------------------------------------------------------------------------------
    $(document).on("click",setup_attendance_worktime_dele_btn,function(){

        //数据ID
        var data_id = zui_datagrid_get_id($(this).attr("rowIndex"));

        //其他操作
        setup_attendance_worktime_dele_submit.attr("dataId",data_id);                                //ID传值
        setup_attendance_worktime_dele_box.modal("show");                                            //面板显示

    });
    //删除提交
    setup_attendance_worktime_dele_submit.click(function(){

        //数据ID
        var data_id = $(this).attr("dataId");

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : { id:data_id },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(setup_attendance_worktime_datagrid_obj,setup_attendance_worktime_api.datagrid);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

});//预加载结尾
</script>